﻿@using Matrix.MaKaYunShang.BLL
@{
    ViewBag.Title = "用户卡券管理";
    ViewBag.PathToBtn = "/UserCard/List";
    ViewBag.TextBtn = "刷新";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                卡券名称：<input type="text" class="form-control input-sm" placeholder="卡券名称" style="width: 110px;display: inline-block" id="keyWord" />
                &nbsp;&nbsp;
                卡券类别：
                <select id="cateId" class="form-control input-sm" style="width: 110px;display: inline-block">
                    <option value="0">全部</option>
                    @{
                        var cateList = CardCategoryBLL.Instance.GetModelList();
                        foreach (var item in cateList)
                        {
                            <option value="@item.Id">@item.CategoryName</option>
                        }
                    }
                </select>
                &nbsp;&nbsp;
                核销状态：
                <select id="status" class="form-control input-sm" style="width: 110px;display: inline-block">
                    <option value="-1">全部</option>
                    <option value="0">未使用</option>
                    <option value="1">已核销</option>
                </select>
                &nbsp;&nbsp;
                领券时间：<input type="text" class="form-control input-sm form_datetime_order_search" placeholder="开始时间" style="width: 110px;display: inline-block" id="startTime" />
                --<input type="text" class="form-control input-sm form_datetime_order_search" placeholder="结束时间" style="width: 110px;display: inline-block" id="endTime" />
                &nbsp;&nbsp;
                <a class="btn btn-primary pull-right" style="margin-left: 10px;" id="btnExport">导出</a>
                <a class="btn btn-primary pull-right" id="btnSearch">查询</a>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                用户卡券列表
            </div>
            <div class="panel-body">
                <div class="dataTable_wrapper">
                    <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                        <thead>
                            <tr>
                                <th>卡券名称</th>
                                <th>卡券类别</th>
                                <th>券码</th>
                                <th>卡券状态</th>
                                <th>领取时间</th>
                                <th>核销时间</th>
                                <th>核销人</th>
                                <th>领取人</th>
                            </tr>
                        </thead>
                        <tbody>                           
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<iframe id="exportFrame" style="display: none"></iframe>

@section javascript{
    <script src="/Content/admin/dist/js/pagingHelper.js"> </script>
    <script type="text/javascript">
        var dataParams = {};
        var serverProcessPath = "/UserCard/Listing";
        var showColumns = [
            { data: "CardName" },
            { data: "CardCategoryName" },
            { data: "CardCode" },
            { data: "CardStatusText" },
            { data: "ShowAddTime" },
            { data: "ShowVerifyTime" },
            { data: "VerifyUserName" },
            { data: "ConsumerNickName" }
        ];
        pagingHelper.Paging(serverProcessPath, dataParams, showColumns);
        $("#dataTables-example_wrapper div:first").hide();

        $(function () {
            $('.form_datetime_order_search').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                weekStart: 1,
                todayBtn: 1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            });

            $("#btnSearch").click(function () {
                reloadList();
            });

            $("#btnExport").click(function() {
                alertify.okBtn("确定").cancelBtn("取消").confirm("将导出当前搜索条件下的所有用户卡券，确定导出吗（导出时间较长，请耐心等候）？", function() {
                    $.post("@Url.Action("ExportUserCards")", "keyWord=" + $("#keyWord").val() + "&cateId=" + $("#cateId").val() + "&status=" + $("#status").val() + "&startTime=" + $("#startTime").val() + "&endTime=" + $("#endTime").val(), function (data) {
                        if (data.Status) {
                            $("#exportFrame").attr("src", data.Message);
                        } else {
                            alertify.alert(data.Message);
                        }
                    });
                });
            });
        });

        function reloadList() {
            pagingHelper.reloadWithDiffPath("@Url.Action("Listing")" + "?keyWord=" + $("#keyWord").val() + "&cateId=" + $("#cateId").val() + "&status=" + $("#status").val() + "&startTime=" + $("#startTime").val() + "&endTime=" + $("#endTime").val());
        }
    </script>
}